package com.example.jnuexperiment2025;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

public class ImageViewActivity extends AppCompatActivity {

    private Button buttonPrevious;
    private Button buttonNext;
    private ImageView imageViewFunny;

    private final int[] imageIDArray = {
            R.drawable.funny_1,
            R.drawable.funny_2,
            R.drawable.funny_3,
            R.drawable.funny_4,
            R.drawable.funny_5,
            R.drawable.funny_6
    };
    private int imageIDArrayCurrentIndex = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_view);

        // 初始化视图
        buttonPrevious = findViewById(R.id.button_previous);
        buttonNext = findViewById(R.id.button_next);
        imageViewFunny = findViewById(R.id.image_view_funny);

        // 设置初始图片
        imageViewFunny.setImageResource(imageIDArray[imageIDArrayCurrentIndex]);

        View.OnClickListener listener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (view.getId() == R.id.button_next) {
                    imageIDArrayCurrentIndex = (imageIDArrayCurrentIndex + 1) % imageIDArray.length;
                } else {
                    imageIDArrayCurrentIndex = (imageIDArrayCurrentIndex - 1 + imageIDArray.length) % imageIDArray.length;
                }
                imageViewFunny.setImageResource(imageIDArray[imageIDArrayCurrentIndex]);
            }
        };

        buttonPrevious.setOnClickListener(listener);
        buttonNext.setOnClickListener(listener);
    }
}